<?php
/**
 * Created by PhpStorm.
 * User: DGH
 * Date: 2017/10/19
 * Time: 11:16
 */
namespace core;
class Load
{
    public static $classMap = array();

    static public function run()
    {
        p('ok');
        $route = new \core\lib\route();
        $ctrlClass = $route->ctrl;
        $action = $route->action;

        $ctrlfile = APP.'/ctrl/'.$ctrlClass.'Ctrl.php';
        $cltrlClass = '\\'.MODULE.'\\ctrl\\'.$ctrlClass.'Ctrl';
        if(is_file($ctrlfile)){
            include $ctrlfile;
            $ctrl = new $cltrlClass();
            $ctrl->$action();
        }else{
            throw new \Exception('找不到控制器'.$ctrlClass);
        }
    }

    static public function autoload($class)
    {
        //自动加载类库
        // new \core\route();
        // $class = '\core\route';
        // IMOOC.'/core/route.php';
        if (isset($classMap[$class])){
            return true;
        }else{
            $class = str_replace('\\','/',$class);
            $file = DGH.'/'.$class.'.php';
            if(is_file($file)){
                include $file;
                self::$classMap[$class] = $class;
            }else{
                return false;
            }
        }
    }
}